package com.common.platform.base.config.mail;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
@Slf4j
public class Main {

    public static void send(String subject, String message) {
        HtmlEmail email = new HtmlEmail();
        try {
            email.setHostName("smtp.qiye.aliyun.com");
            email.setCharset("UTF-8");
            for (String str : Collections.singleton("446150793@qq.com")) {
                email.addTo(str);
            }
            email.setFrom("m@yonrd.com", "雍正");
            email.setSmtpPort(25);
            email.setAuthentication("m@yonrd.com", "User12345");
            email.setSubject(subject);
            email.setMsg(message);
            email.send();
            log.info("{} 发送邮件到 {}", "m@yonrd.com", StringUtils.join("446150793@qq.com", ","));
        } catch (EmailException e) {
            log.error("m@yonrd.com" + "发送邮件到" + StringUtils.join("446150793@qq.com", ",") + "失败", e);
        }
    }

    public static void main(String[] args) {
        send("hello", "hello");
    }
}

